/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.game.entity.enemy;

import ace.system.Utilities;
import ace.system.xml.XmlNode;
import ace.system.xml.XmlReaderWriter;
import java.util.Hashtable;

/**
 *
 * @author Hallucinogen
 */
public class EnemyFactory {
	private EnemyFactory() {
		mEnemyDictionary = new Hashtable();
		XmlNode XML = XmlReaderWriter.getInstance().readFromXmlFile(Utilities.ENEMY_FILE);

		//For each child
		for (int i = 0; i < XML.getChildren().size(); i++) {
			//Get child
			XmlNode Child = (XmlNode)XML.getChildren().elementAt(i);

			//Check name
			if (Child.getNodeName().equals("enemy")) {
				//Prepare variable
				int Index		= Integer.parseInt(Child.getAttribute("index"));

				//Save to dictionary
				if (Index >= 0) mEnemyDictionary.put(new Integer(Index), new EnemyData(Child));
			}
		}
	}

	public static EnemyFactory instance() {
		if (sInstance == null) {
			sInstance = new EnemyFactory();
		}
		return sInstance;
	}

	public EnemyData getEnemyData(int index) {
		return (EnemyData)mEnemyDictionary.get(new Integer(index));
	}

	private Hashtable mEnemyDictionary;

	// singleton
	private static EnemyFactory sInstance = null;
}
